function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
l1 = new ListNode();
l1 = new ListNode();
var addTwoNumbers = function(l1, l2) {
    let cur = new ListNode();
    let res = cur;
    while (l1 || l2) {
        if (l1 == null) { res.next = l2; return res }
        if (l2 == null) { res.next = l1; return res }
        while (l1.val >= l2.val) {
            res.next = l1;
            l1 = l1.next;
            res = res.next;
        }
        while (l1.val < l2.val) {
            res.next = l2;
            l2 = l2.next;
            res = res.next;
        }
    }
    return res;
}

//递归
var mergeTwoLists = function(l1, l2) {
    if (!l1) return l2;
    if (!l2) return l1;
    if (l1.val < l2.val) {
        l1.next = mergeTwoLists(l1.next, l2);
        return l1;
    } else {
        l2.next = mergeTwoLists(l1, l2.next);
        return l2;
    }
}